<?php
namespace app\common\customer\model;

use app\common\config\logic\DictionaryLogic;
use app\common\config\model\ConfigStatus;
use app\common\config\model\ConfigStore;
use app\common\system\logic\UserLogic;
use think\model\concern\SoftDelete;

class CustomerHotel extends \think\Model
{
    protected $table = "tk_member_hotel";
    use SoftDelete;
    protected $autoWriteTimestamp = true;
    protected $defaultSoftDelete = 0;

    // 分配人
    public function getFromUserAttr($value, $data)
    {
        $logic = new UserLogic();

        return $logic->getUser($data['from_user_id'], ['id', 'realname', 'status']);
    }

    // 当前任务的跟踪者
    public function getUserAttr($value, $data)
    {
        $logic = new UserLogic();

        return $logic->getUser($data['user_id'], ['id', 'realname', 'status']);
    }

    public function getHotelAttr($value, $data)
    {
        $logic = new DictionaryLogic();
        $hotel = $logic->getItem($data['hotel_id'], ConfigStore::class, ['id', 'title']);

        return $hotel;
    }

    public function getVisitStatusAttr($value, $data) {
        $dictionaryLogic = new DictionaryLogic();
        $row = $dictionaryLogic->getItem($data['status'], ConfigStatus::class, ['id','title']);
        if (empty($row)) {
            $row = [
                'id' => 0,
                'title' => '待跟进'
            ];
        }

        return $row;
    }
    
}